class Device {
    device;
    name;
    type;
    instanceId;
    left;
    top;
    width;
    height;
    imageUrl;
    color;
    rotateDeg;
    reverse;

    constructor(config) {
        const { device, name, type, imageUrl = '', width = 60, height = 60, color = '#000', rotateDeg = 0, reverse = 0 } = config;
        // 实例id，确保唯一
        this.instanceId = `device-${Date.now()}-${Math.random()}`
        this.device = device
        this.name = name
        // 设备类型：设备/开关
        this.type = type,
        // 初始位置，默认值
        this.left = 0;
        this.top = 0;
        this.width = width;  
        this.height = height; 
        this.imageUrl = imageUrl
        this.color = color
        this.rotateDeg = rotateDeg
        this.reverse = 0
    }

    getName() {
        return this.name
    }

    getDevice() {
        return this.device
    }

    getInstanceId() {
        return this.instanceId
    }


    // 更新实例ID
    updateInstanceId() {
        this.instanceId = `device-${Date.now()}-${Math.random()}`
    }

    // 更新位置
    updateLocation(top, left) {
        this.top = top
        this.left = left
    }

    // // 设备与设备建立联系
    // connectTo(device) {
    //     this.connections.push(device)
    // }

    // // 更新与设备相关的其他设备属性（比如连线设备）
    // updateConnectedDevices(propertyName, newValue) {
    //     this.connections.forEach(conn => {
    //         conn.updateProperty(propertyName, newValue);
    //     });
    // }

    // // 设备属性变化时更新关联的其他设备
    // updateProperty(propertyName, newValue) {
    //     if (this.properties[propertyName] !== undefined) {
    //         this.properties[propertyName] = newValue;
    //         this.updateConnectedDevices(propertyName, newValue);
    //     }
    // }
}

export default Device